@php
$app=app('wechat');
$js=$app->js;
$user=\App\Member::find(Auth::guard('member')->id());
@endphp
<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js" type="text/javascript" charset="utf-8"></script>

<script src="{{asset('statics/js/layer/layer_mobile/layer.js')}}" type="text/javascript" charset="utf-8"></script>
<script>

    var  type={{$type}};
    var  is_bind={{$combo->is_bind}};
    var  mobile='{{$user->mobile}}';
    var return_url='{{url()->full()}}';

    //调用微信JS api 支付
    function jsApiCall()
    {
        layer.open({type: 2});
        $.post('/payfor',{type:{{$type}},combo_id:{{$combo_id or 0}},total_num:total_num},function(data){
          //  alert(JSON.stringify(data));
            WeixinJSBridge.invoke(
                'getBrandWCPayRequest',data.msg,
                function(res){
                    if(mobile=='15036158397') {
                       alert(JSON.stringify(res));
                    }
                    layer.closeAll();
                    if(res.err_msg=="get_brand_wcpay_request:cancel"){
                        return '';
                    }
                    if(res.err_msg=="get_brand_wcpay_request:ok"){
                        layer.open({
                            content: '支付成功'
                            ,btn: '我知道了'
                        });
                        if(type==1){
                            location.href="";
                        }else{
                            layer.open({
                                content: '支付成功',
                                btn: '确定',
                                shadeClose: false,
                                yes: function(){
                                    //location.href="/user/combo?out_trade_no="+data.out_trade_no ;
                                    location.href="/user/combo" ;
                                }
                            });

                        }
                    }else{
                        layer.open({
                            content: JSON.stringify(res)
                            ,btn: '我知道了'
                        });
                    }

                }
            );
        })
        return ;
    }
    function callpay()
    {

        if(type==2&&is_bind==1&&mobile==''){//
            layer.open({
                content: '请绑定你的手机号',
                btn: '确定',
                shadeClose: false,
                yes: function(){
                    location.href="/user/profile?return_url="+return_url ;
                }
            });
            return ;
        }
        if (typeof WeixinJSBridge == "undefined"){
            if( document.addEventListener ){
                document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);
            }else if (document.attachEvent){
                document.attachEvent('WeixinJSBridgeReady', jsApiCall);
                document.attachEvent('onWeixinJSBridgeReady', jsApiCall);
            }
        }else{
            jsApiCall();
        }
    }
</script>